<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>购物订单管理</title>
<meta name="decorator" content="default" />
<style type="text/css">
	.select2-container{
		width:163px;
	}
	table_tbody th,td:nth-last-of-type(2){
		max-width:100px;
		white-space:nowrap;
		overflow:hidden;
		text-overflow:ellipsis;
	}
</style>

<script type="text/javascript">
		//查看物流
		function showLogisticsModal(id){
			$("#Logisticsinfo li").remove();
			$("#myModalLabel").html('');
			$.ajax({
			    url:'${ctx}/shop/order/manage/getlogistics',
			    type:'POST',
			    dataType:'json',
			    data:{id:id},
			    success:function(data){
				    if(data!=null && data!=''){
				    	$('#LogisticsOrder').modal("show");
				    	if(data.Estimateddeliverytime!=null && data.Estimateddeliverytime!='')
				    	    $("#myModalLabel").html("预计到达时间："+data.Estimateddeliverytime);
				        var traces=data.traces;
				        var Remark='';
				        for(var i=0;i<traces.length;i++){
					        
				        	if(traces[i].Remark!=null && traces[i].Remark!=''){
				        		Remark="。备注：" +traces[i].Remark;
                            }
					        if(i==0){
					        	$("#Logisticsinfo").append(" <li class='first' > <i class='node-icon'></i><span class='txt'>状态："+data.state+
							        	";</span><span class='time'> "+
							        	traces[i].AcceptTime+";</span>"+"<span class='txt'>"+traces[i].AcceptStation + ""
							        	+Remark +"</span></li>");
					        }else{
						        
					        	$("#Logisticsinfo").append(" <li > <i class='node-icon'></i><span class='time'> "+
	                                    traces[i].AcceptTime+";</span>"+"<span class='txt'>"+traces[i].AcceptStation +""+Remark+ "</span></li>");
						     }
					     }
				    }
                }
				})
		}
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
	<style type="text/css">
	   .first{
	       color: red
	   }
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active">
			<c:choose>
				<c:when test="${shopOrder.status == '1'}"><a href="#">待付款</a></c:when>
				<c:when test="${shopOrder.status == '2'}"><a href="#">已付款</a></c:when>
				<c:when test="${shopOrder.status == '3'}"><a href="#">已确认</a></c:when>
				<c:when test="${shopOrder.status == '4'}"><a href="#">已发货</a></c:when>
				<c:when test="${shopOrder.status == '5'}"><a href="#">交易完成</a></c:when>
				<c:when test="${shopOrder.status == '6'}"><a href="#">取消</a></c:when>
				<c:otherwise>
					<a href="${ctx}/shop/order/manage/">购物订单列表</a>
				</c:otherwise>
			</c:choose>
		</li>
	</ul>
	<form:form id="searchForm" modelAttribute="shopOrder" action="${ctx}/shop/order/manage/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />
		<ul class="ul-form">
			<li><label>订单编号：</label> <form:input path="code" htmlEscape="false" maxlength="64" class="input-medium" /></li>
			<li><label>创建时间：</label> <input name="createTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate" 
				value="<fmt:formatDate value="${shopOrder.createTime}" pattern="yyyy-MM-dd"/>"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</li>
			<li>
				<label>订单状态：</label> 
				<%-- <form:input path="status" htmlEscape="false" maxlength="4" class="input-medium" /> --%>
				<form:select path="status">
	                <option value="">--请选择--</option>
                    <form:option value="1">待付款</form:option>
	                <form:option value="2">已付款</form:option>
	                <form:option value="3">已确认</form:option>
	                <form:option value="4">已发货</form:option>
	                <form:option value="5">交易完成</form:option>
	                <form:option value="6">已取消</form:option>
	                <form:option value="7">申请退款</form:option>
	                <form:option value="8">退款驳回</form:option>
	                <form:option value="9">退款成功</form:option>
	                <form:option value="10">退款失败</form:option>
	            </form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" /></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}" />
	<table id="contentTable"
		class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>订单编号1</th>
				<th>收货人</th>
				<th>订单总金额</th>
				<th>商品总金额</th>
				<th>下单人联系电话</th>
				<th>配送费</th>
				<th>配送方式</th>
				<th>订单状态</th>
                <th>支付时间</th>
                <th>是否删除</th>
				<th>创建时间</th>
				<th>备注信息</th>
				<shiro:hasPermission name="shop:order:manage:edit">
					<th>操作</th>
				</shiro:hasPermission>
			</tr>
		</thead>
		<tbody class="table_tbody">
			<c:forEach items="${page.list}" var="shopOrder">
				<tr>
					<td><a
						href="${ctx}/shop/order/manage/form?id=${shopOrder.id}">
							${shopOrder.code} </a></td>
					<td>${shopOrder.shopOrderReceiving.name}</td>
					<td>${shopOrder.totalAmount}</td>
					<td>${shopOrder.totalAmountProduct}</td>
					<td>${shopOrder.account.telNum}</td>
					<td>${shopOrder.freight}</td>
					<td>
						<c:forEach items="${logisticsCodes }" var="logisticsCode">
	                            <c:if test="${shopOrder.shopOrderReceiving.company eq logisticsCode.logisticsCode}">
	                                 ${logisticsCode.logisticsCompany}
	                            </c:if>
	                     </c:forEach> 
					      <%--  ${shopOrder.shopOrderReceiving.company} --%>
					</td>
					<td><c:choose>
							<c:when test="${shopOrder.status == '1'}">待付款</c:when>
							<c:when test="${shopOrder.status == '2'}">已付款</c:when>
							<c:when test="${shopOrder.status == '3'}">已确认</c:when>
							<c:when test="${shopOrder.status == '4'}">已发货</c:when>
							<c:when test="${shopOrder.status == '5'}">交易完成</c:when>
							<c:when test="${shopOrder.status == '6'}">取消</c:when>
							<c:when test="${shopOrder.status == '7'}">申请退款</c:when>
							<c:when test="${shopOrder.status == '8'}">驳回申请退款</c:when>
							<c:when test="${shopOrder.status == '9'}">申请退款成功</c:when>
							<c:when test="${shopOrder.status == '10'}">申请退款失败</c:when>
						</c:choose></td>
                    <td><fmt:formatDate value="${shopOrder.payTime}" pattern="yyyy-MM-dd" /></td>
                    <td>
                         <c:choose>
							<c:when test="${shopOrder.isDeleted == '0'}">否</c:when>
							<c:when test="${shopOrder.isDeleted == '1'}">是</c:when>
						</c:choose>
					</td>
					<td><fmt:formatDate value="${shopOrder.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>${shopOrder.comment}</td>
					<shiro:hasPermission name="shop:order:manage:edit">
						<td><a
							href="${ctx}/shop/order/manage/form?id=${shopOrder.id}">修改</a>
							<a href="${ctx}/shop/order/manage/delete?id=${shopOrder.id}"
							onclick="return confirmx('确认要删除该购物订单吗？', this.href)">删除</a>
							<c:if test="${shopOrder.status == '4' || shopOrder.status == '5'}">
							     <a href="javascript:void(0);" onclick="showLogisticsModal('${shopOrder.id}')">物流信息</a>
							</c:if>
							<c:if test="${shopOrder.status == '7' || shopOrder.status == '10'}">
								<a href="${ctx}/shop/order/manage/refund?id=${shopOrder.id}">申请退款</a>
							</c:if>
							<c:if test="${shopOrder.status == '2' }">
								<a href="${ctx}/shop/order/manage/refund?id=${shopOrder.id}">退款</a>
							</c:if>
							</td>
					</shiro:hasPermission>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	
	<!-- 物流信息 开始 -->
        <div class="modal fade" id="LogisticsOrder" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                   <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel"></h4>
                    </div>
                    <div class="modal-body">
                        <div class="col-xs-12">
                            <div class="row">
                              <ul id="Logisticsinfo">
                              </ul>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer"></div>
                </div>
            </div>
        </div>
        
        <!-- 物流信息 结束 -->
</body>
        

</html>